package com.beyond.trace.dy.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.beyond.trace.dy.domain.TraceDyProduce;
import com.beyond.trace.dy.service.ITraceDyProduceService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 生产加工单Controller
 * 
 * @author Mr.Yao
 * @date 2022-04-09
 */
@RestController
@RequestMapping("/dy/produce")
@Api(value = "生产加工单", tags = "生产加工单")
public class TraceDyProduceController extends BaseController
{
    @Autowired
    private ITraceDyProduceService traceDyProduceService;

    //@PreAuthorize("@ss.hasPermi('dy:produce:list')")
    @GetMapping("/list")
    @ApiOperation("查询生产加工单列表")
    public TableDataInfo list(TraceDyProduce traceDyProduce)
    {
        startPage();
        List<TraceDyProduce> list = traceDyProduceService.selectTraceDyProduceList(traceDyProduce);
        return getDataTable(list);
    }

    //@PreAuthorize("@ss.hasPermi('dy:produce:query')")
    @GetMapping(value = "/query")
    @ApiOperation("查询生产加工单列表不分页")
    public AjaxResult getInfoQuery(TraceDyProduce traceDyProduce)
    {
        return AjaxResult.success(traceDyProduceService.selectTraceDyProduceList(traceDyProduce));
    }

    //@PreAuthorize("@ss.hasPermi('dy:produce:export')")
    @Log(title = "生产加工单", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(TraceDyProduce traceDyProduce)
    {
        List<TraceDyProduce> list = traceDyProduceService.selectTraceDyProduceList(traceDyProduce);
        ExcelUtil<TraceDyProduce> util = new ExcelUtil<TraceDyProduce>(TraceDyProduce.class);
        return util.exportExcel(list, "生产加工单数据");
    }

    //@PreAuthorize("@ss.hasPermi('dy:produce:query')")
    @GetMapping(value = "/{produceId}")
    @ApiOperation("查询生产加工单列表")
    public AjaxResult getInfo(@PathVariable("produceId") Long produceId)
    {
        return AjaxResult.success(traceDyProduceService.selectTraceDyProduceById(produceId));
    }

    //@PreAuthorize("@ss.hasPermi('dy:produce:add')")
    @Log(title = "生产加工单", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation("新增生产加工单")
    public AjaxResult add(@RequestBody TraceDyProduce traceDyProduce)
    {
        return toAjax(traceDyProduceService.insertTraceDyProduce(traceDyProduce));
    }

    //@PreAuthorize("@ss.hasPermi('dy:produce:edit')")
    @Log(title = "生产加工单", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation("修改生产加工单")
    public AjaxResult edit(@RequestBody TraceDyProduce traceDyProduce)
    {
        return toAjax(traceDyProduceService.updateTraceDyProduce(traceDyProduce));
    }

    //@PreAuthorize("@ss.hasPermi('dy:produce:remove')")
    @Log(title = "生产加工单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{produceIds}")
    @ApiOperation("删除生产加工单")
    public AjaxResult remove(@PathVariable Long[] produceIds)
    {
        return toAjax(traceDyProduceService.deleteTraceDyProduceByIds(produceIds));
    }
}
